//
//  LPSanHuiYKListDetailViewController.m
//  GongXinDangJian
//
//  Created by 刘应平 on 2017/12/4.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "LPSanHuiYKListDetailViewController.h"
#import "STPhotoBroswer.h"
@interface LPSanHuiYKListDetailViewController ()
/**  会议时间  */
@property (strong, nonatomic) UILabel  *meetTime;
/**  会议内容  */
@property (strong, nonatomic) UILabel  *meetContent;
/**  学习内容  */
@property (strong, nonatomic) UILabel  *studyContent;
/**  会议类型  */
@property (strong, nonatomic) UILabel  *meetType;
/**  会议照片  */
@property (strong, nonatomic) UILabel  *meetPhote;
/**    */
@property (strong, nonatomic) UIScrollView  *backScrollView;
/**  图片数据  */
@property (strong, nonatomic) NSArray  *MSG_RES;
/**  图片  */
@property (strong, nonatomic) NSMutableArray  *imageNames;

/**  最后一个视图  */
@property (strong, nonatomic) UIView  *lastView;

@end

@implementation LPSanHuiYKListDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titlelabel.text = self.model.NAME;
    [self getData];
   
}

- (void)getData{
    [LPRequestManager request_miitactionShykActiongetShykResWithMSG_ID:self.model.ID TYPE_VALUE:self.model.TYPE_VALUE successBlock:^(id object) {
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE integerValue] == 20000) {
            NSArray *array = [object objectForKey:@"SHYKS"];
            self.model = [LPSanHuiMeetingListModel yy_modelWithJSON:array[0]];
            self.MSG_RES = [object objectForKey:@"MSG_RES"];
             [self layoutUI];
        }else{
            [[LPShowNoDataManager showNoDataManager] showEmptyViewWithView:self.view Type:1];
            [LPShowNoDataManager showNoDataManager].noContentViewTapedBlock = ^{
                [self getData];
            };
        }
    } failBlock:^(id object) {
        [[LPShowNoDataManager showNoDataManager] showEmptyViewWithView:self.view Type:1];
        [LPShowNoDataManager showNoDataManager].noContentViewTapedBlock = ^{
            [self getData];
        };
    }];
}

#pragma mark - 界面
- (void)layoutUI{
    [self.view addSubview:self.backScrollView];
    [self.backScrollView addSubview:self.studyContent];
    [self.backScrollView addSubview:self.meetTime];
    [self.backScrollView addSubview:self.meetType];
    [self.backScrollView addSubview:self.meetContent];
    [self.backScrollView addSubview:self.meetPhote];
    
    NSString *studyString = [NSString stringWithFormat:@"%@  %@",@"学习内容 :",self.model.NAME];
    CGFloat studyHeight = [CalculateLabelHeight CalculateLabelHeightWithString:studyString font:17 * [UIScreen zj_textFontScale] width:[UIScreen zj_screenWith] - 40 * [UIScreen zj_screenWScale]].height;
    self.studyContent.sd_layout
    .leftSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.backScrollView, 30 * [UIScreen zj_screenHScale])
    .heightIs(studyHeight);
    
    self.studyContent.attributedText = [self attributedStringForm:[NSString string:self.model.NAME isNilStringReturnDeftString:@"暂无"] markString:@"学习内容 :"];
    
    
    NSString *timeString = [NSString stringWithFormat:@"%@  %@",@"会议时间 :",self.model.UPDATETIME];
    CGFloat timeHeight = [CalculateLabelHeight CalculateLabelHeightWithString:timeString font:17 * [UIScreen zj_textFontScale] width:[UIScreen zj_screenWith] - 40 * [UIScreen zj_screenWScale]].height;
    self.meetTime.sd_layout
    .leftSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.studyContent, 10 * [UIScreen zj_screenHScale])
    .heightIs(timeHeight);
    
    self.meetTime.attributedText = [self attributedStringForm:[NSString string:self.model.PUBLISH_DATE isNilStringReturnDeftString:@"暂无"] markString:@"会议时间 :"];
    
    
    NSString *meetTypeString = [NSString stringWithFormat:@"%@  %@",@"会议类型 :",self.model.TYPE_TEXT];
    CGFloat meetTypeHeight = [CalculateLabelHeight CalculateLabelHeightWithString:meetTypeString font:17 * [UIScreen zj_textFontScale] width:[UIScreen zj_screenWith] - 40 * [UIScreen zj_screenWScale]].height;
    self.meetType.sd_layout
    .leftSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.meetTime, 10 * [UIScreen zj_screenHScale])
    .heightIs(meetTypeHeight);
    
    self.meetType.attributedText = [self attributedStringForm:[NSString string:self.model.TYPE_TEXT isNilStringReturnDeftString:@"暂无"] markString:@"会议类型 :"];
    
    
    NSString *meetcontentString = [NSString stringWithFormat:@"%@  %@",@"会议内容 :",self.model.CONTENT];
    CGFloat meetContentHeight = [CalculateLabelHeight CalculateLabelHeightWithString:meetcontentString font:17 * [UIScreen zj_textFontScale] width:[UIScreen zj_screenWith] - 40 * [UIScreen zj_screenWScale]].height;
    self.meetContent.sd_layout
    .leftSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.meetType, 10 * [UIScreen zj_screenHScale])
    .heightIs(meetContentHeight);
    
    self.meetContent.attributedText = [self attributedStringForm:[NSString string:self.model.CONTENT isNilStringReturnDeftString:@"暂无"] markString:@"会议内容 :"];
    
    
    self.meetPhote.sd_layout
    .leftSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self.backScrollView, 20 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.meetContent, 10 * [UIScreen zj_screenHScale])
    .heightIs(15 * [UIScreen zj_screenHScale]);
    self.meetPhote.text = @"会议照片 :";
    self.lastView = self.meetPhote;
    CGFloat tottalheight = studyHeight + timeHeight + meetTypeHeight + meetContentHeight + 110 * [UIScreen zj_screenHScale];
    
    CGFloat width = ([UIScreen zj_screenWith] - 90 * [UIScreen zj_screenWScale]) / 3;
    for (int i = 0; i < self.MSG_RES.count; i ++) {
        NSDictionary *dic = self.MSG_RES[i];
        NSInteger yu = i % 3;
        NSInteger zheng = i / 3;
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(30 * [UIScreen zj_screenWScale] + (width + 15 * [UIScreen zj_screenWScale]) * yu, tottalheight + (width + 10 * [UIScreen zj_screenHScale]) * zheng, width, width)];
        [imageView sd_setImageWithURL:CREATEURL(dic[@"RES_URL")] placeholderImage:PlaceholderImage];
        [self.imageNames addObject:[NSString stringWithFormat:@"%@",dic[@"RES_URL"]]];
        imageView.userInteractionEnabled = YES;
        imageView.tag = i;
        [self.backScrollView addSubview:imageView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)];
        [imageView addGestureRecognizer:tap];
        
        self.lastView = imageView;
        
    }
    
    [self.backScrollView setupAutoContentSizeWithBottomView:self.lastView bottomMargin:30 * [UIScreen zj_screenHScale]];
    
    
}

- (void)tapImage:(UITapGestureRecognizer *)tap{
    STPhotoBroswer *view = [[STPhotoBroswer alloc]initWithFrame:CGRectMake(0, 0,self.view.width , self.view.height) ImageArray:self.imageNames currentIndex:tap.view.tag];
    [view show];
}

- (NSAttributedString *)attributedStringForm:(NSString *)string markString:(NSString *)markString{
    NSString *allString = [NSString stringWithFormat:@"%@  %@",markString,string];
    //创建一个属性字符串
    NSMutableAttributedString *headerMutableString = [[NSMutableAttributedString alloc]initWithString:allString];
    
    //开始根据长度和位置 设置颜色
    [headerMutableString addAttribute:NSForegroundColorAttributeName value:[UIColor textBlackColor] range:NSMakeRange(markString.length, string.length)];
    [headerMutableString addAttribute:NSForegroundColorAttributeName value:[UIColor zj_colorWithHexString:@"a8a8a8"] range:NSMakeRange(0, markString.length)];
    
    return headerMutableString;
}


#pragma mark - getter
- (UILabel *)studyContent{
    if (!_studyContent) {
        _studyContent = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(17);
            label.numberOfLines = 0;
            label;
        });
    }
    return _studyContent;
}


- (UILabel *)meetTime{
    if (!_meetTime) {
        _meetTime = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(17);
            label.numberOfLines = 0;
            label;
        });
    }
    return _meetTime;
}

- (UILabel *)meetType{
    if (!_meetType) {
        _meetType = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(17);
            label.numberOfLines = 0;
            label;
        });
    }
    return _meetType;
}

- (UILabel *)meetContent{
    if (!_meetContent) {
        _meetContent = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(17);
            label.numberOfLines = 0;
            label;
        });
    }
    return _meetContent;
}

- (UILabel *)meetPhote{
    if (!_meetPhote) {
        _meetPhote = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor zj_colorWithHexString:@"a8a8a8"];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(17);
            label;
        });
    }
    return _meetPhote;
}

- (UIScrollView *)backScrollView{
    if (_backScrollView == nil) {
        _backScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, navHeight, self.view.width, self.view.height - navHeight)];
    }
    return _backScrollView;
}

- (NSMutableArray *)imageNames{
    if (_imageNames == nil) {
        _imageNames = [NSMutableArray array];
    }
    return _imageNames;
}
@end
